#!/bin/bash

# if [[ `which sed` ]]; then
# 	echo "gun sed"
# else
# 	echo "please install gun sed"
# fi

# mac安装gunSed  http://blog.csdn.net/sun_wangdong/article/details/71078083
which_sed=`which sed`
echo $which_sed
echo "testresult = $(expr $which_sed : '.*/gnu-sed/')"
if [[ $(expr $which_sed : '.*/gnu-sed/') -gt 0 ]]; then
	echo "检测到使用gun sed"
else
	if [ ! `which brew` ]
	then
		echo 'Homebrew not found. Trying to install...'
                    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
			|| exit 1
	fi
	echo 'Trying to install gun sed...'
	brew install gnu-sed --with-default-names || exit 1
	# 设置局部环境变量
	echo "set PATH...."
	source ./set-gun-sed-path.sh
	echo "set PATH done"
fi

	echo "请手动执行命令："
	command="PATH=\"/usr/local/Cellar/gnu-sed/4.4/bin:\$PATH\""
	echo -e "\033[31m $command \033[0m"
	echo ""


# if [ ! `which sed` ]
# then
# 	echo 'sed not found'
# 	if [ ! `which brew` ]
# 	then
# 		echo 'Homebrew not found. Trying to install...'
#                     ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
# 			|| exit 1
# 	fi
# 	echo 'Trying to install sed...'
# 	brew install gnu-sed --with-default-names || exit 1
# 	export PATH="PATH=/usr/local/Cellar/gnu-sed/4.4/bin:$PATH"
# fi

# /usr/local/Cellar/gnu-sed/4.4/bin/sed